// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import axios from 'axios'
Vue.prototype.$axios = axios
 import Mint from 'mint-ui'
 Vue.use(Mint)
import 'mint-ui/lib/style.css'
import 'font-awesome/css/font-awesome.css'
import store from './store'
var state=store.state;
const mutations = {
changeLogin(state,data){
    state.isLogin = data;
}
};
import Home from './components/index'
import Course from './components/course'
import Message from './components/message'
import Login from './components/login'
import Mine from './components/mine'
import Coursedetail from './components/courseDetail'
import Msgdetail from './components/messageDetail'
import Mycollect from './components/mycollect'
Vue.config.productionTip = false
let bus = new Vue()
Vue.prototype.bus = bus
let router = new VueRouter({
  linkActiveClass:'mui-active',
  mode: 'history',
  routes: [

//      //VueRouter：配置路由规则
     // { path: '/', redirect: { name: 'home' } }, //重定向
     { name: 'home', path: '/', component: Home },//首页
     { name:'course',path:'/course',component: Course}, //课程
     { name: 'message',path:'/message',component:Message}, //留言
     { name: 'login',path:'/login',component:Login}, //登录
     { name: 'mine',path:'/mine',component:Mine,
     meta: {
requireAuth: true // 添加该字段 ( 字段名可以自定义 )，表示进入这个路由是需要登录的
}},   
     { name: 'mycollect',path:'/mycollect',component:Mycollect}, //我的收藏
     { name: 'detail',path:'/detail',component:Coursedetail}, //课程详情
     { name: 'msgdetail',path:'/msgdetail',component:Msgdetail}, //信息详情
     //{ name:'news.list',path:'/news/list',component:NewsList}, //新闻列表
////      { name:'news.detail',path:'/news/detail',component:NewsDetail}, //新闻详情
////      { name:'photo.share',path:'/photo/share',component:PhotoShare}, //图文分享
////      { name:'photo.detail',path:'/photo/detail/:id',component:PhotoDetail},//图片详情
////      { name:'goods.list',path:'/goods/list', component:GoodsList}, //商品列表
////      { name:'goods.detail',path:'/goods/detail',component:GoodsDetail}, //商品详情
////      { name:'goods.comment',path:'/goods/comment',component:GoodsComment},//商品评论
////      { name:'goods.pictureInfo',path:'/goods/pictureinfo',component:NewsDetail},//图文介绍
  ]
});
Vue.filter('ellipsis',function(value){
	return value.slice(0,14)+"...";
})
Vue.filter('ymd',function(value){
	return value.slice(0,10);
})
router.beforeEach(function(to,form,next){
	var logged_in=false;
	var logged=state.isLogin;
	
	if(!logged_in&&to.meta.requireAuth&&logged==0){
			next('/login');
			 console.log("进入登录页面")
	}
	else{
		next();
		//return logged;
         console.log("进入我的页面")
	}
});
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

